Repository navigation
fix(core): make LikeC4 patching string- and comment-aware and default to model-edits - #410
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 57 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
64892dd to
53682bb
Compare
[Medium impact] The PR reaches architecture-model patching and the analysis and check flows. The comment-boundary issue should be fixed before merging. Findings
SummaryThis PR makes model patching aware of strings and comments and makes LikeC4 model edits the default.
No new findings. Reviews (4) · Last reviewed commit: "fix(core): do not treat URL paths as com..." · Reviewed by Greptile |
bd672b0 to
84bb5de
Compare
| // inside an unquoted token. Unquoted URIs such as `link https://x.io/api/*` contain `//` and | ||
| // `/*`, and mistaking them for comments would hide every later closing brace. Real comments in | ||
| // models are always written after whitespace or a brace, so this is the safest boundary. | ||
| const commentMayStart = (at: number): boolean => at === 0 || /[\s{};]/.test(text.charAt(at - 1)); |
There was a problem hiding this comment.
Adjacent comments break text patches.
commentMayStart rejects comments immediately after a closing quote, even though a = service 'A'// } is valid LikeC4. The scanner then treats the comment's } as the end of model. With the text strategy and no accepted AI patch, deterministicInsert splits that comment line at the brace, adds the relationships, and turns the commented brace into a real closing brace. Any following elements fall outside model, so validation rejects the whole patch. Recognize comments after quoted strings while keeping comment-like text inside unquoted URLs intact.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…g models
- Dotted new-component IDs now become `extend <parent> { <leaf> = ... }` in
the text path, sharing componentDefinition with the model-edits diff block.
Before, `a.b.c = service` failed validation and dropped the whole patch.
- Model blocks are found by a `model` keyword at line start followed by `{`,
possibly on the next line, so `extend x.datamodel {` no longer counts.
- New dsl-scanner masks '...', "...", '''...''', // and /* */ before brace
matching, used by deterministicInsert, quickValidatePatch and
findTargetFile. Replaces closingBraceOnSameLine.
- quickValidatePatch checks multi-line entries line by line, and
deterministicInsert re-indents them as a unit.
`adapter.likec4.patchStrategy` now defaults to `model-edits`; `text` stays selectable and is still the fallback whenever model edits return no patch. Tests about text patching pin `text` explicitly. Regenerates both config schemas, updates the configuration reference and amends ADR-012.
Structurizr strings use double quotes only and lines starting with # are comments, so an apostrophe such as "# Bob's workspace" no longer masks the model block. quickValidatePatch takes the format's scan options as an optional fourth argument. ADR-012 amendment now notes that text-path insertedLines can still differ from LikeC4's placement under model-edits.
- Keep // after : as part of an unquoted URI, not a line comment
- Find model blocks after a BOM and after { or ; on the same line
- Quick-validate by brace delta and require inserted entries as contiguous blocks
- Place the model-edits diff file in the selected LikeC4 project's folder
- Ignore -> in comments and strings when picking the target file
- Indent entries one level inside an empty or split model block
Comments now open only at a token boundary (line start, whitespace, or one
of { } ;), so unquoted URIs containing // or /* no longer hide later braces.
84bb5de to
74e414d
Compare
Stacked on #409.
What changed
extend parent { child = ... }in text patching. Before,a.b.c = service ...was invalid DSL and the whole patch, relationships included, was dropped.adapters/dsl-scanner.ts): masks strings (',",''') and comments before counting braces, sodescription 'a } b',// }and/* } */no longer misplace inserts.//after:(unquotedlink https://...) is not a comment.model {at a statement start, after a BOM, or after{/;on the same line (workspace "x" { model {).extend x.datamodel {and elements namedmodelno longer match.cacheout of itsextendblock is now rejected.adapter.likec4.patchStrategydefaults tomodel-edits; text patching stays the fallback. In multi-project workspaces model-edits writes into the selected project, or falls back to text when none is selected.->inside comments or strings no longer drives target-file choice; inserts into an empty or one-linemodelblock are indented. Structurizr uses the same scanner with double quotes and#comments.Behaviour changes
model-editsis the default LikeC4 patch strategy.modelblock in a file.Review follow-ups
//and/*start a comment only at a token boundary, so unquoted URLs such aslink https://x.io/api/*no longer mask braces.Checks
check:ci